package cn.com.git.admin.dao.impl;

import cn.com.git.common.base.BaseDaoImpl;
import cn.com.git.admin.dao.SysKeyValueDAO;
import cn.com.git.admin.dao.mapper.SysKeyValueMapper;
import cn.com.git.admin.dao.model.SysKeyValue;
import cn.com.git.admin.dao.model.SysKeyValueExample;
import cn.com.git.admin.service.query.SysKeyValueListQuery;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
/**
  * SysKeyValueDAO接口
  * @author zhangzhenfu
  * @Description
  * @date 2020/5/18
*/
@Repository
public class SysKeyValueDAOImpl extends BaseDaoImpl<SysKeyValueMapper,SysKeyValue,SysKeyValueExample,SysKeyValueListQuery,Integer> implements SysKeyValueDAO {

    @Autowired
    private SysKeyValueMapper mapper;

    @Override
    protected SysKeyValueMapper getMapper() {
        return mapper;
    }

    @Override
    public SysKeyValueExample analysisLimit(SysKeyValueListQuery query) {
        SysKeyValueExample example = new SysKeyValueExample();
        SysKeyValueExample.Criteria c =  example.createCriteria();
        //TODO
        return example;
    }

    @Override
    public SysKeyValue selectById(Integer id) {
        return super.selectByPrimaryKey(id);
    }

    @Override
    public SysKeyValue selectOne(SysKeyValueListQuery query) {
        SysKeyValueExample example = analysisLimit(query);
        //TODO
        List<SysKeyValue> list =   Optional.ofNullable(super.selectByExample(example)).orElse(Lists.newArrayList());
            if(list.size()>0){
                return list.get(0);
            }
        return null;
    }

    @Override
    public List<SysKeyValue> selectList(SysKeyValueListQuery query) {
        SysKeyValueExample example = analysisLimit(query);
        return Optional.ofNullable(super.selectByExample(example)).orElse(Lists.newArrayList());
    }

    @Override
    public int countLimit(SysKeyValueListQuery query) {
        SysKeyValueExample example = analysisLimit(query);
        return countByExample(example);
    }

    @Override
    public Integer insertOne(SysKeyValue record) {
        super.insertSelective(record);
        return record.getId();
    }

    @Override
    public List<SysKeyValue> insertList(List<SysKeyValue> list) {
        Optional.ofNullable(list).orElse(Lists.newArrayList()).forEach(s->{
            super.insertSelective(s);
        });
        return list;
    }

    @Override
    public Integer updateOne(SysKeyValue record) {
        return super.updateByPrimaryKeySelective(record);
    }

    @Override
    public Integer updateLimit(SysKeyValue record, SysKeyValueListQuery query) {
        SysKeyValueExample example = analysisLimit(query);
        return super.updateByExampleSelective(record,example);
    }

    @Override
    public Integer deleteOne(Integer id) {
        return super.deleteByPrimaryKey(id);
    }

    @Override
    public Integer deleteLimit(SysKeyValueListQuery query) {
        SysKeyValueExample example = analysisLimit(query);
        return super.deleteByExample(example);
    }

}